#pragma once
#include "Gui_References.h"
#include "worldTextBox.h"
#include "../Global References/EngineResources.h"
#include "GUI_Morph.h"

class Engine;
#define itemList Vector<Item_Base*>&
#define menuSet Vector<gui_base*>&
#define ALLOW_PRELOADING //Uncomment to prevent the proloading option from being clicked at gamestart

class GUI_Handler
{
public:
	enum messageSets{
		IPADDRESS,
		SCORE,
		CHATBOXINPUT,
		CHATBOXOUTPUT,
		NOTIFICATION,
		AUTOLOOTINFO,
		MOUSEOVER,		
		SIZE_MESSAGES
	};
	enum guiItemSets{
		INVENTORY,
		EQUIPMENT,
		CRAFTABLE,
		HOTKEY,
	};

private:
	enum menuAssets
	{
		sAlpha,
		//PIE
		sPierceChit,
		sImpactChit,
		sEnergyChit,
		sMetaChit,
		sScore,
		//Tutorials
		tutControls,
		tutHelpControls,
		tutMusic,
		tutInventory,
		tutCrafting,
		tutHealth,
		tutWin,
		//Panels
		sMouseOver,
		sMainSplash,		
		sTransChatBox,		
		multiplayerMenu,
		craftingMenu,
		InventoryMenu,
		controlsMenu,
		miniSquare,
		//Input
		sIPInputBox,
		sTransInput8x2,		
		//Buttons
		menuButton,
		menuAssetsSize
	};

	/*=====HEALTH=====*/
	Vector3D playerDefenses;
	Vector3D playerDamage;
	Vector3D playerHealth;
	gui_panel* pierceHUD;
	gui_panel* impactHUD;
	gui_panel* energyHUD;
	gui_panel* metaHUD;
	/*=====HANDLING INVENTORY=====*/
	bool refreshInventory;
	gui_panel* mouseOverPanel;		//Displays text of itemMoused over
	Vector3D playerInvMessage;		//X = Inventory icon pressed, Y =	Intended action (3D: Z = Which list)
	Vector<gui_base*> Inventory;	//What the player currently has
	Vector<gui_base*> Equipment;	//What the player is currently wearing
	Vector<gui_base*> CrafTable;	//What the player can craft
	Vector<gui_base*> CraftRecipes;	//What the player can craft (Recipes in detail)

	/*=====NOTIFICATION=====*/
	bool waitAStepToUndoNotification;
	stopWatch notificationCheck;

	/*=====HANDLING TUTORIAL=====*/
	int currentTutorial;
	Vector<gui_base*> Tutorials;

	/*=====HANDLING TEXT=====*/
	char Message;				//The keystroke passed in from game, wiped in update
	char* mBox[SIZE_MESSAGES];
	worldTextBox m_WorldText;

	/*=====UPDATE VARIABLES=====*/
	short lastButtonClicked;	//Stores the ID of the last Gui_button clicked, wiped in update
	short lastGameState;		//If this changes, update the game
	bool needToUpdate;			

	/*=====MOUSEOVER=====*/
	char* generateInventoryMouseOverText	(Item_Base* Item);
	char* generateRecipeMouseOverText		(Item_Base* Item, int Index);
	bool handleMouseOver		(short currentState, gui_panel* Piece, POINT Mouse);
	bool handleMouseOver		(short currentState, menuSet List, POINT Mouse);
	void handlePIEMouseOver		(short currentState, POINT Mouse);

	/*======LISTS=====*/
	Vector<gui_base*> menuList;
	Vector2D assets[menuAssetsSize];

	/*=====PRIVATE INITS=====*/
	void initAssets();
	void initList(menuSet List, int size);
	void initIntroMenu();			//STATE_INTRO_MENU
	void initLoadMultiGameMenu();	//STATE_MULTI_GAME_SELECT
	void initGamePlayMenu();		//STATE_GAME
	void initTutorialMenu();		//STATE_GAME
	void initControlsMenu();		//STATE_GAME_CONTROLS
	void initGameChatMenu();		//STATE_GAME_CHAT
	void initGameInventory();		//STATE_GAME_INVENTORY
	void initGameCrafting();		//STATE_GAME_CRAFT
	/*=====PRIVATE UPDATES=====*/
	void handleMultiGameMessages();
	void handleGameChatMessage	();
	void handleInGameMessage	();
	void handleMessages			(short currentState);
	void updateList				(short currentState,short listID, Vector<gui_base*> toUpdate);
	/*=====PRIVATE MESSAGE HANDLING=====*/
	void  addWorldMessage			(char* Message);
	char* polishMultiplayerMessage	(char* Message);
	char* preparePlayerPrefix		(int index);
	void  enterMessage();


public:
	static GUI_Handler& get(){static GUI_Handler G;return G;}
	int errorMessageIndex;

	//=====CORE FUNCTIONS
	void initialize();
	void update(short currentState, POINT mouse);	
	void release();

	//=====HEALTH
	void setPIE(Vector3D PIE);							//To display the player's Health
	void setMeta(float percentBlue);
	void setMaxHealth(Vector3D PIE);
	void setDamage(Vector3D PIE);
	void setDefenses(Vector3D PIE);		

	//=====Message Handling
	void setMessage(char a_message);
	void setMessage(char* a_message, messageSets list);							//Displays the message where desired
	void setMessage(int foreValue, char* appendedMessage,messageSets list);		//Appends the values together and displays them where desired
	void setMessage(char* foreValue, char* appendedMessage,messageSets list);	//Appends the values together and displays them where desired
	void clearMessage(messageSets list);
	
	//=====Mutators
	void changeTextBoxString(int index, char* a_message);
	void itdBeCoolIfYouUpdated(){needToUpdate = true;};

	//=====Clicking
	void checkIconCollision(short currentState, menuSet toUpdate, POINT mouse, bool shiftClicked);
	void checkCollision(short currentState,POINT mouse, bool shiftClicked);

	//===Chatbox
	void deactivateChatbox();

	//===Inventory
	void setInventory(itemList Inventory);
	void setRecipeList(Vector<gui_base*> &RecipeList);
	void setCrafTable(itemList Inventory);
	void setEquipment(Item_Base* equipList[], int Size);

	//===Tutorial
	void resetTutorials();
	void stopTutorials();

	//=====ACCESSORS
	bool		needsToRefreshInventory(){return refreshInventory;}
	short		getLastButtonClicked()	{return lastButtonClicked;};
	Vector3D	getPlayerInvMessage()	{return playerInvMessage;};
	int			getWorldTextBoxCount()	{return m_WorldText.totalCharCount();};

	//=====Multiplayer
	char*		getTextByIndex(messageSets index);


};